package com.dwjm.shop.utils;

import java.sql.DriverManager;

public class ConnectionDatabaseForMySQLUseJDBC {
    //连接数据库的驱动
    private static final String DRIVER = "com.mysql.cj.jdbc.Driver";
    //连接数据库的url
    private static final String URL = "jdbc:mysql://localhost:3306/sshop?useSSL=false&serverTimezone=UTC";
    //连接数据库的用户
    private static final String USER = "root";
    //连接数据库的密码
    private static final String PASSWORD = "123456";

    //定义数据库连接对象
    private static java.sql.Connection connection = null;
    //连接数据库的函数
    public static java.sql.Connection getConnection() {
        try {
            Class.forName(DRIVER);
            connection = DriverManager.getConnection(URL, USER, PASSWORD);
            return connection;
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
    //测试数据库是否可以连接
    public static void main(String[] args) {
        System.out.println(getConnection() == null);
//        System.out.println(connection);
    }

}
